package sc.client;

import k8.Logic;
import k8.k8;

public final class FPS extends Logic
{
	// Frames per second
	public static int fps;
	
	// The single instance of Interface
	private static FPS instance = null;
	
	private long lastupdate;
	private long elapsed;
	private float secs;

	/** Prevent public construction of FPS */
	private FPS()
	{
		// Update once per second
		setUpdateRate(1);
	}
	
	/**
	 * Creates a single instance of Interface.
	 */
	public static void initialise()
	{
		if (instance == null)
			instance = new FPS();
	}
	
	public void update(long time) {
        // Calculate elapsed time
        elapsed = time - lastupdate;
        lastupdate = time;
        
        // Update fps value
        secs = (float) elapsed / 1000000000;
        FPS.fps = Math.round((float)k8.frame()/secs);
    }
}
